/**
 * 
 */
package br.com.locasis.view.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import br.com.locasis.utilitarios.UtilString;

/**
 * @author rlresende
 * 
 */
@org.jboss.seam.annotations.faces.Converter
@Name("placaConverter")
@BypassInterceptors
public class PlacaConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		String str = null;
		if (value == null || value.trim().length() == 0) {
			return str;
		}
		str = value.replace("-", "");
		return str;
	}

	@SuppressWarnings("static-access")
	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		if (!(value instanceof String)) {
			return "";
		}
		return UtilString.getInstance().formatarPlaca(value.toString());
	}

}
